package cn.hm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Queue;
import javax.jms.Topic;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/8/1 12:07
 */
@RestController
@RequestMapping("/msg")
public class MqSendController {

    @Autowired
    private Topic topic;

    @Autowired
    private Queue queue;

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;


    @RequestMapping("/sendQueue")
    public String sendQueue(String msg) {
        jmsMessagingTemplate.convertAndSend(queue, msg);
        return "队列消息发送成功：" + Thread.currentThread().getName();
    }

    @RequestMapping("/sendTopic")
    public String sendTopic(String msg) {
        jmsMessagingTemplate.convertAndSend(topic, msg);
        return "主题消息发送成功：" + Thread.currentThread().getName();
    }
}
